package com.wyth.lottery.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/9/6.
 */

public abstract class BaseFragment extends Fragment implements StateLayout.OnErrorListener {

    protected StateLayout stateLayout;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        if (stateLayout == null) {

            stateLayout = new StateLayout(getActivity());
            //设置successView
            stateLayout.setSuccessView(getSuccessView());

            ButterKnife.bind(this, stateLayout);
            //默认显示loading界面
            //   stateLayout.showLoadingView();
            stateLayout.setOnErrorClickListener(this);
            //加载数据
            initDate();

        } else {

            ViewGroup parent = (ViewGroup) stateLayout.getParent();
            if (parent != null) {
                parent.removeView(stateLayout);
            }

        }
        return stateLayout;
    }



    protected abstract View getSuccessView();

    protected abstract void initDate();

    @Override
    public void onErrorClick() {
        initDate();
    }

}
